package org.study.controller;

import dev.langchain4j.model.chat.ChatModel;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: jzhou
 * @date: 2025/7/5-10:24
 * @version: 1.0
 * @description: java-ai-study
 */
@RestController
@Slf4j
public class HelloLangChain4JController {
    @Resource(name = "qwen")
    private ChatModel chatModelQwen;
    @Resource(name = "deepseek")
    private ChatModel chatModelDeepSeek;

    // 访问地址：http://localhost:8080/langchain4j/hello?prompt=你是谁
    @GetMapping(value = "/langchain4j/hello")
    public String hello(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt){
        String chat = chatModelQwen.chat(prompt);
        System.out.println("通过langchain4j调用模型返回结果：\n" + chat);
        return chat;
    }

    // http://localhost:8080/multimodel/deepseek?prompt=你是谁
    @GetMapping(value = "/multimodel/deepseek")
    public String deepseekCall(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt)
    {
        String result = chatModelDeepSeek.chat(prompt);

        System.out.println("通过langchain4j调用模型返回结果：\n"+result);

        return result;
    }

}
